import request from '@/utils/request'
import type { ResponseData } from '@/types/common'
import type { Review, CreateReviewDto } from '@/types/review'

// 创建评价
export const createReview = (data: CreateReviewDto) => {
  return request.post<ResponseData>(`/orders/${data.order_id}/review`, data)
}

// // 获取订单评价
// export const getOrderReview = (orderId: number) => {
//   return request.get<{
//     code: number
//     data: Review
//     message: string
//   }>(`/reviews/order/${orderId}`)
// }

// 获取评价列表
export const getReviews = (params?: {
  keyword?: string
  rating?: number
  page?: number
  pageSize?: number
}) => {
  return request.get<{
    code: number
    data: {
      items: Review[]
      meta: {
        total: number
        page: number
        pageSize: number
        totalPage: number
      }
    }
    message: string
  }>('orders/reviews/list', { params })
}

// 删除评价
export const deleteReview = (orderId: number) => {
  return request.delete<ResponseData>(`/orders/reviews/${orderId}`)
}
